package mypackage;


import java.util.Scanner;
import java.util.zip.CheckedOutputStream;

public class ReverseString {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入String or Int");

        String str=sc.next();
        String strStr="String";
        String strInt="Int";

        if(str.equalsIgnoreCase(strStr)){
            //是字符串反转
            String ans=reverseString();
            System.out.println("反转后为:"+ans);
        }else if(str.equalsIgnoreCase(strInt)){
            //是数字反转
            int ans=reverseInt();
            System.out.println("反转后为:"+ans);
        }else {
            System.out.println("输入了非法字符");
        }
    }
    public static String reverseString(){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入字符串");
        String str=sc.next();
        String newstr="";
        for (int i = 0; i < str.length(); i++) {
            char c=str.charAt(i);
            newstr=c+newstr;
        }
        return newstr;
    }
    public static int reverseInt(){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入数字");
        int num=sc.nextInt();
        boolean flag=true;
        if(num<0){
            flag=false;
            num=num*-1;
        }
        int temp=num;
        int newnum=0;
        while(temp>0){
            int tempNum=temp%10;
            newnum=newnum*10+tempNum;
            temp/=10;
        }
        if(flag==false){
            newnum=-1*newnum;
        }
        return newnum;
    }
}
